from django.shortcuts import render

# Create your views here.
from rest_framework.response import Response
from rest_framework.views import APIView

from users.models import User


class RegisterUsernameAPIView(APIView):
    def get(self,request,username):
        """
        判断用户是否注册
        查询用户的数量
        itcast 0   没有注册
        itcast 1   有注册
        """
        count = User.objects.filter(username=username).count()
        # 返回数据
        return Response({
            'count':count,
            'username':username
        })

class RegisterPhoneCountAPIView(APIView):
    def get(self,request,mobile):
        count = User.objects.filter(mobile=mobile)
        context = {
            'count':count,
            'phone':mobile
        }
        return Response(context)